//
//  DeploymentDetailsMetricsController.m
//  jboss-admin
//
//  Created by Christos Vasilakis on 06/07/2010.
//  Copyright 2010 All rights reserved.
//

#import "DeploymentDetailsMetricsController.h"
#import "ProgressViewController.h"

@implementation DeploymentDetailsMetricsController

@synthesize metrics;
@synthesize results;
@synthesize index;

- (void)viewDidLoad {
	[super viewDidLoad];
	
	NSArray *array = [[[results objectForKey:@"deployment"] objectAtIndex:self.index] objectForKey:@"statistics"];
	self.metrics = array;
	
	[array release];
	
	NSLog(@"DeploymentDetailsSummaryController viewDidLoad");
}

- (void)viewDidUnload {
	[super viewDidUnload];
	
	self.metrics = nil;
	self.results = nil;
	
	NSLog(@"DeploymentDetailsSummaryController viewDidUnload");
}

- (void)dealloc {
	[metrics release];
	[results release];
	
	NSLog(@"DeploymentDetailsSummaryController deAlloc");
	
	[super dealloc];
}

#pragma mark -
#pragma mark Table Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	return [self.metrics count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView  cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	static NSString *MetricCellIdentifier = @"MetricCellIdentifer";
	
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MetricCellIdentifier];
	
	if (cell == nil) {
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MetricCellIdentifier] autorelease];
		
		UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 160, 25)];
		label.tag = kLabelTag;
		label.textAlignment = UITextAlignmentRight;
		label.font = [UIFont boldSystemFontOfSize:12.0];
		label.textColor = kNonEditableTextColor;
		
		[cell.contentView addSubview:label];
		[label release];
		
		UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(190, 10, 190, 25)];
		textField.tag = kTextFieldTag;
		textField.font = [UIFont boldSystemFontOfSize:20.0];
		textField.userInteractionEnabled = NO;
		
		[cell.contentView addSubview:textField];
		[textField release];
	}
	
	NSUInteger row = [indexPath row];
	
	UILabel *label = (UILabel *) [cell viewWithTag:kLabelTag];
	UITextField *textField = (UITextField *) [cell viewWithTag:kTextFieldTag];
											  
	NSDictionary *metric = [self.metrics objectAtIndex:row];

	label.text =  [[metric objectForKey:@"name"] stringByAppendingString:@":"];
	textField.text = [metric objectForKey:@"value"];
	
	return cell;
}

#pragma mark -
#pragma mark Table Delegate Methods
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	//NSUInteger row = [indexPath row];
	
	/*
	 if ([[self.options objectAtIndex:row] isEqualToString:@"Web Applications"]) {
	 
	 } else {
	 UIAlertView *alert = [[UIAlertView alloc]
	 initWithTitle: @"Not implemented yet..."
	 message:nil
	 delegate:nil
	 cancelButtonTitle:@"Cancel"
	 otherButtonTitles:nil];
	 [alert show];
	 [alert release];
	 }
	 */
	
	[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (IBAction)refresh {
	NSLog(@"DeploymentDetailsMetricsController refresh");

}

@end